<style lang="scss" scoped>
  .current{
      margin-top: 0.937vw;
      .title{
        font-size: 0.833vw;
        font-family: PingFang SC;
        font-weight: 400;
        color: #00D1E3;
        opacity: 1;
        margin-bottom: 0.625vw;
        line-height: 1.145vw;
      }
      .box{
        width: 23.75vw;
        padding-bottom:0.312vw;
        .th{
          width: 23.75vw;
          height: 1.98vw;
          background: rgba(4, 146, 164, 0.1);
          opacity: 1;
          span{
            width: 4.53vw;
            font-size: 0.677vw;
            font-family: PingFang SC;
            font-weight: 400;
            line-height: 1.98vw;
            color: #00D1E3;
            text-align: center;
            display: inline-block;
          }
          span:first-child{
            width: 4.43vw;
          }
          span:nth-child(2){
            width: 5.73vw;
          }
        }
        .body{
          height: 11.98vw;
          overflow-y: hidden;
          .lis{
            position: relative;

            .li{
              display: flex;
              align-items: center;
              height: 2.396vw;
              span{
                width: 4.53vw;
                font-family: PingFang SC;
                font-weight: 400;
                line-height: 1.98vw;
                text-align: center;
                display: inline-block;
                font-size: 0.625vw;
                color: #E3E3E3;
                line-height:2.396vw;
                opacity: 1;
              }
              span:first-child{
                width: 4.43vw;
              }
              span:nth-child(2){
                width: 5.73vw;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
              }
            }
          }
          .stopTrans{
            transition: bottom 2s ease;
          }
        }
        .body::-webkit-scrollbar {display:none}
      }
}
</style>
<template>
    <div class="current">
      <div class="title">实时投放播报</div>
      <div class="box bot_s">
        <div class="th">
          <span>设备号</span>
          <span>地址</span>
          <span>投递次数</span>
          <span>垃圾类型</span>
          <span>垃圾重量</span>
        </div>
        <div class="body ">
          <div class="lis" :style="{bottom}" :class="stopTransCurrentFlag? 'stopTrans': ''" ref="lis">
            <div class="li" v-for="item in currentData">
              <span>{{item.deviceCode}}</span>
              <span>{{item.address}}</span>
              <span>{{item.deliverNumber}}</span>
              <span>{{item.garbageTypeName}}</span>
              <span>{{item.weight}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

</template>

<script>
import { mapGetters } from "vuex";
import moment from 'moment'
import {getGarbageSortDeviceStatistics, listRealTimeDeliverReport,
  listRealTimeFaultReport
} from "@/api/screem";
export default {
  data() {
    return {
      initTimer: null,
      frontData: {},
      currentData: [],
      currentDataOrigin: [],
      stopTransCurrentFlag: true,
      currentDataIndex: 0,
      currentTimer:null,
      currentTmp: [],
    };
  },
  created() {
   this.pullInit()
  },
  computed: {
    bottom() {
      return this.currentDataIndex *  2.396+ "vw"; //定义移动的单元高度
    }
  },
  mounted() {
    this.transCurrent()
  },
  props: [],
  components: {},
  methods: {
    pullInit() {
      this.init()
      this.initTimer = setInterval(() => {
        this.init()
      }, 60000)
    },
    transCurrent() {
      this.currentTimer = setInterval(_ => {
        //自定义滚动 出勤率
        if (this.currentDataIndex < 10 /* this.towerListArr.length */) {
          this.currentDataIndex += 1;
        } else {
          this.stopTransCurrentFlag = false
          if (this.currentTmp.length) {
            this.currentTmp.forEach(i => {
              this.currentData.splice(-5,0 ,i)
            })
            this.currentTmp = []
          }
          setTimeout(() => {
            this.currentDataIndex = 0;
            setTimeout(() => {
              this.stopTransCurrentFlag = true
            }, 1000)
          }, 1000)
        }
      }, 3000);
    },
    init() {

      listRealTimeDeliverReport()
        .then(res => {
          if (this.currentData.length > 100) {
            this.currentDataOrigin = (res.data || []).reverse()
            this.currentData = this.currentDataOrigin.concat(this.currentDataOrigin.slice(0,5))
            return
          }

          if (this.currentDataOrigin.length === 0) {
            this.currentDataOrigin = (res.data || []).reverse()
          } else {
            this.currentTmp = (res.data || []).filter(item => item.id > this.currentData[this.currentData.length - 6].id)
          }
          if (this.currentData.length === 0) {
            this.currentData = this.currentDataOrigin.concat(this.currentDataOrigin.slice(0,5))
          }
        })

    }
  }
};
</script>


